package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CpBom;
import com.ruoyi.system.service.ICpBomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * BOM管理Controller
 * 
 * @author GGJ
 * @date 2024-05-20
 */
@RestController
@RequestMapping("/system/bom")
public class CpBomController extends BaseController
{
    @Autowired
    private ICpBomService cpBomService;

    /**
     * 查询BOM管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(CpBom cpBom)
    {
        startPage();
        List<CpBom> list = cpBomService.selectCpBomList(cpBom);
        return getDataTable(list);
    }

    /**
     * 导出BOM管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:bom:export')")
    @Log(title = "BOM管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpBom cpBom)
    {
        List<CpBom> list = cpBomService.selectCpBomList(cpBom);
        ExcelUtil<CpBom> util = new ExcelUtil<CpBom>(CpBom.class);
        util.exportExcel(response, list, "BOM管理数据");
    }

    /**
     * 获取BOM管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cpBomService.selectCpBomById(id));
    }

    /**
     * 新增BOM管理
     */
    @PreAuthorize("@ss.hasPermi('system:bom:add')")
    @Log(title = "BOM管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpBom cpBom)
    {
        return toAjax(cpBomService.insertCpBom(cpBom));
    }

    /**
     * 修改BOM管理
     */
    @PreAuthorize("@ss.hasPermi('system:bom:edit')")
    @Log(title = "BOM管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpBom cpBom)
    {
        return toAjax(cpBomService.updateCpBom(cpBom));
    }

    /**
     * 删除BOM管理
     */
    @PreAuthorize("@ss.hasPermi('system:bom:remove')")
    @Log(title = "BOM管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cpBomService.deleteCpBomByIds(ids));
    }
}
